/* 
 * File:   systask.h
 * Author: apleilx
 */

#ifndef SYSTASK_H
#define	SYSTASK_H

#include "stdint.h"
#include "dataproc.h"
#include "rtctime.h"
#include "pulse.h"

#ifdef   _SYSTASK_MODULE_
#define  SYS_EXT
#else
#define  SYS_EXT  extern
#endif  	
	
#ifdef	__cplusplus
extern "C" {
#endif

#define rang_check(val, min, max)   ((val<=max) && (val >= min))


typedef struct
{
    uint32_t ct2;
    uint32_t uart0;
    uint32_t uart2;
} sys_clock_type;

    typedef struct 
    {
        uint8_t b_run_st;
        volatile uint32_t g_uTicks;
        timer_pulse_type pulse;
        TIME_Type time;
        sig_time_type    sig_time;
        bcd_time_type    bcd_time;
        
        uint32_t mem_addr_stack;
        uint32_t mem_addr_stack_end;
        uint32_t mem_addr_heap;
        uint32_t mem_addr_heap_end;
        
        sys_clock_type clock;
        uint16_t temp_sv;
        float f_temp_air;
        
        union
        {
            uint16_t tb[32];
            struct
            {
                uint16_t p;
                uint16_t i;
                uint16_t d;
                uint16_t r;        
                uint16_t t;
            } ps;
        } pid; 
        
        union
        {
            uint16_t tb[32];
            struct
            {
                uint16_t temp_rd;
                uint16_t temp_ad;
                float f_temp;
                
                uint16_t t_out_period;
                uint16_t t_out_duty;
            } ps;
        } par;
        
    } sys_st_type;
    
    SYS_EXT sys_st_type sysst __attribute__((section(".app_mem.")));
    
void sys_task (void   *argument);
    
#ifdef	__cplusplus
}
#endif


#undef SYS_EXT

#endif	/* SYSTASK_H */

